package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import service.UrlGeneratorService;
import util.NumberTransfer;

/**
 * Created by YanYang on 2015/12/28.
 */
@Controller
@RequestMapping(value = "")
public class TinyUrlVisit {
    @Autowired
    public TinyUrlVisit(UrlGeneratorService urlGeneratorService){
        this.urlGeneratorService = urlGeneratorService;
    }
    private UrlGeneratorService urlGeneratorService;
    @RequestMapping(value = "/{urlID}",method = RequestMethod.GET)
    public String tinyUrlVisit(@PathVariable("urlID") String urlID_62, Model model){

        long urlID_10 = NumberTransfer._62to10(urlID_62);
        String normalUrl = urlGeneratorService.getNormalUrlByUrlID(urlID_10);
        System.out.println(normalUrl);
        return "redirect:"+normalUrl;
    }
}
